package com.plwf.lake.service.impl;

import com.plwf.lake.entity.Power;
import com.plwf.lake.mapper.PowerMapper;
import com.plwf.lake.service.PowerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
@Service
public class PowerServiceImpl implements PowerService{
    @Resource
    private PowerMapper mapper;

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean save(Power bean) {
        if(bean.getId()!=null){
            return mapper.update(bean);
        }else{
            return mapper.insert(bean);
        }
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean remove(Integer id) {
        return mapper.delete(id);
    }

    @Override
    public Power find(Integer id) {
        return mapper.selectOne(id);
    }

    @Override
    public List<Power> query() {
        return mapper.select();
    }

    @Override
    public boolean saveXh(Map<String, Integer> map) {
        return mapper.updateXh(map);
    }

    @Override
    public List<Power> query2() {
        return mapper.select2();
    }

    @Override
    public List<Power> queryAll() {
        return mapper.selectAll();
    }
}
